package source.model;

import java.util.Hashtable;
import java.util.Vector;

import source.model.type.*;

public class BaseData implements GameData{

	private Hashtable<String, Base> dataList;
	private final GameObjectType dataType = GameObjectType.BASE;
	
	public BaseData() {
		dataList = new Hashtable<String, Base>();
	}
	
	public boolean dataMatch( GameObjectType got ) {//only guarantees that the object is of type STRUCTURE
		return dataType.equals( got );
	}
	
	public boolean addObject( GameObject go ) {
		if ( dataMatch( go.objectType() ) && !dataList.containsKey( go.objectID() ) )
		{
			Base b = dataList.put( go.objectID().getID(), (Base) go );
			if ( b != null) return false;
			return true;
		}
		else
			return false;
	}
	
	public Base getObject( ObjectID id ) {
		return dataList.get( id.getID() );
	}
	
	public boolean removeObject( GameObject go ) {
		return !(dataList.remove( go.objectID().getID() ) == null);
	}
	
	public Vector<GameObject> getAllObjects (GameObjectType got)
	{
		if(this.dataType == got)
		{
		Vector<GameObject> v = new Vector<GameObject>();
		for( Base b : dataList.values() )
		{
		v.add(b);
		}
		return v;
		}
		else
			return null;	
	}
}
